import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/commom/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/

/**
 * 懒加载路由
 */
const login = resolve => require(['../views/commom/login/index'], resolve);
const notFoundPage = resolve => require(['../views/404'], resolve);
const register = resolve => require(['../views/commom/register/index'], resolve);
const forgot = resolve => require(['../views/commom/forgot/index'], resolve);


//两种角色都有的路由/页面
export const constantRouterMap = [
    { path: '/login', component: login, hidden: true },
    { path: '/register', component: register, hidden: true },
    { path: '/forgot', component: forgot, hidden: true },
    { path: '/404', component: notFoundPage, hidden: true }
];



//平台路由
/**
 * role - 权限
 * admin - 平台
 * proxy - 自营商户
 * Depositor - 寄存商户
 * @type {[*]}
 */
export const asyncRouterMap = [
  // 库存模块
  {
    path: '',
    component: Layout,
    redirect: '/addInventory',
    meta: { title: '库存管理', icon: 'example', role: ['admin'] },
    children: [
      {
        path: 'addInventory',
        name: 'addInventory',
        component: () => import('@/views/inventory/addInventory/index'),
        meta: { title: '添加库存', icon: 'dashboard', role: ['admin'] }
      },
      {
        path: 'setInventory',
        name: 'setInventory',
        meta: { title: '修改库存', icon: 'dashboard', role: ['admin'] },
        component: () => import('@/views/inventory/setInventory/index')
      }
    ]
  },

    // 商家管理模块
  {
    path: '/sellerManger',
    component: Layout,
    redirect: '/sellerManger/join',
    // name: 'sellerManger',
    meta: { title: '商家管理', icon: 'example', role: ['admin'] },
    children: [
      {
        path: 'join',
        name: 'join',
        redirect: 'approval',
        component: () => import('@/views/sellerManger/join/index'),
        meta: { title: '商家管理', icon: 'user', role: ['admin'] },
        children:[
          {
            path: 'approval',
            name: 'approval',
            component: () => import('@/views/sellerManger/join/approval'),
            meta: { title: '商家入驻审批',icon: 'user', role: ['admin'] }

          },
          {
            path: 'details',
            name: 'details',
            component: () => import('@/views/sellerManger/join/details/index'),
            hidden: true,
            meta: { title: '商家入驻详情',icon: 'user', role: ['admin'] }
          }
        ]

      },
      {
        path: 'hasJoin',
        name: 'hasJoin',
        component: () => import('@/views/sellerManger/hasJoin/index'),
        meta: { title: '商家管理', icon: 'tree' ,role: ['admin']},
        children:[
          {
            path: 'approval',
            name: 'approval2',
            component: () => import('@/views/sellerManger/hasJoin/approval'),
            meta: { title: '已入驻商家管理',icon: 'user', role: ['admin'] }

          },
          {
            path: 'details',
            name: 'details2',
            component: () => import('@/views/sellerManger/hasJoin/hasJoinDetails/index'),
            hidden: true,
            meta: { title: '查看详情',icon: 'user', role: ['admin'] }
          },
          {
            path: 'details/taking',
            name: 'taking',
            component: () => import('@/views/sellerManger/hasJoin/record/taking'),
            hidden: true,
            meta: { title: '提货记录',icon: 'user', role: ['admin'] }
          },
          {
            path: 'details/setting',
            name: 'taking2',
            component: () => import('@/views/sellerManger/hasJoin/record/setting'),
            hidden: true,
            meta: { title: '提货记录',icon: 'user', role: ['admin'] }
          }
        ]
      }
    ]
  },

  // 待配送模块
  {
    path: '/goodsManager',
    component: Layout,
    redirect: '/goodsManager/waitingDelivery',
    meta: { title: '配货管理', icon: 'example', role: ['admin'] },
    children: [
      {
        path: 'waitingDelivery',
        name: 'waitingDelivery',
        component: () => import('@/views/goodsManager/waitingDelivery'),
        meta: { title: '待配货', icon: 'dashboard', role: ['admin'] },
      },
      {
        path: 'waitingDelivery/details',
        name: 'waitingDeliveryDetails',
        component: () => import('@/views/goodsManager/waitingDelivery/details/index'),
        hidden: true,
        meta: { title: '待配货详情', icon: 'dashboard', role: ['admin'] }
      },
      {
        path: 'goodsRecord',
        name: 'goodsRecord',
        meta: { title: '配货记录', icon: 'dashboard', role: ['admin'] },
        component: () => import('@/views/goodsManager/goodsRecord')
      }
    ]
  },

  // 结算
  {
    path: '/adminSettlement',
    component: Layout,
    // redirect: 'adminSettlement',
    meta: { title: '结算', icon: 'example', role: ['admin'] },
    children: [
      {
        path: 'adminSettlement',
        name: 'adminSettlement',
        component: () => import('@/views/adminSettlement'),
        meta: { title: '结算', icon: 'example', role: ['admin'] },
      },
    ]
  },




  //-----------------------------------------平台的路由写在上面，商家端的写在下面 --------------------------------


  {
    //个人资料
    path:"profile",
    name: 'profile',
    redirect: '/index',
    component: Layout,
    meta: { title: '', icon: 'example', role: ['Depositor','proxy'] },
    children:[
      {
        path: 'index',
        name: 'profile-index',
        meta: { title: '个人资料', icon: 'dashboard', role: ['Depositor','proxy'] },
        component: () => import('@/views/profile/index'),
      }
    ]
  },


  {
    //套餐管理
    path:"/packageManager",
    name: 'packageManager',
    redirect: 'add',
    component: Layout,
    meta: { title: '套餐管理', icon: 'example', role: ['Depositor','proxy'] },
    children:[
      {
        path: 'add',
        name: 'add',
        meta: { title: '新增套餐', icon: 'dashboard', role: ['Depositor','proxy'] },
        component: () => import('@/views/packageManager/add/index'),
      },
      {
        path: 'modify',
        name: 'modify',
        meta: { title: '修改套餐', icon: 'dashboard', role: ['Depositor','proxy'] },
        component: () => import('@/views/packageManager/modify/index'),
      }
    ]
  },


  {
    //配货申请
    path:"/pickingManager",
    name: 'pickingManager',
    redirect: 'add',
    component: Layout,
    meta: { title: '配货申请', icon: 'example', role: ['Depositor','proxy'] },
    children:[
      {
        path: 'add',
        name: 'addpicking',
        meta: { title: '申请配货', icon: 'dashboard', role: ['Depositor','proxy'] },
        component: () => import('@/views/pickingManager/add/index'),
      },
      {
        path: 'list',
        name: 'listpicking',
        meta: { title: '待配货列表', icon: 'dashboard', role: ['Depositor','proxy'] },
        component: () => import('@/views/pickingManager/list/index'),
      },
      {
        path: 'history',
        name: 'historypicking',
        meta: { title: '配货历史', icon: 'dashboard', role: ['Depositor','proxy'] },
        component: () => import('@/views/pickingManager/history/index'),
      },

      {
        path: 'detail',
        name: 'historydetail',
        hidden:true,
        meta: { title: '配货详情', icon: 'dashboard', role: ['Depositor','proxy'] },
        component: () => import('@/views/pickingManager/detail/index'),
      }
    ]
  },

  {
    path:"/bill",
    name: '',
    component: Layout,
    meta: { title: '结算', icon: 'example', role: ['Depositor','proxy'] },
  },

  //结算
  {
    path:"/bill",
    name: 'businessBill',
    redirect: '/index',
    component: Layout,
    meta: { title: '', icon: 'example', role: ['Depositor','proxy'] },
    children:[
      {
        path: 'index',
        name: 'bill-index',
        meta: { title: '结算', icon: 'dashboard', role: ['Depositor','proxy'] },
        component: () => import('@/views/businessBill/index'),
      },
      {
        path: 'detail',
        name: 'bill-detail',
        meta: { title: '结算详情', icon: 'dashboard', role: ['Depositor','proxy'] },
        hidden:true,
        component: () => import('@/views/businessBill/detail/index'),
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }



]


export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

